<template>


	<view ref="container">
		<view class="cardwaibao">
			<view class="card1">
				<image class="card1img" :src="pic" mode="aspectFill"></image>
			</view>
			<view class="card2">
				<input type="text" class="duihuaninput" placeholder="请输入兑换卡密" v-model="cardPswd" />
				<view class="duihuanbtn" @tap="duihuan()">兑换</view>
			</view>
			<view class="card3">
				<view class="card3title">活动介绍：</view>
				<view class="card3content">
					{{text}}
				</view>
			</view>
		</view>
	</view>


</template>
<script>
	import {
		mapGetters,
	} from "vuex";
	import Recommend from "@/components/Recommend";
	import {
		yxConfigget,
		exchangeCardexchange
	} from "@/api/user";
	import Loading from "@/components/Loading";
	export default {
		name: "GoodsFoot",
		components: {
			Recommend,
			Loading
		},
		props: {},
		data: function() {
			return {
				
				cardPswd: '',
				pic: '',
				text: '',
				url: '',
			};
		},
		computed: mapGetters(["userInfo"]),
		mounted: function() {
			this._yxConfigget()
		},

		methods: {

			duihuan() {
				var that = this

				if (that.cardPswd === '') {
					uni.showToast({
						title: "请输入卡密",
						icon: "none",
						duration: 2000,
						complete: () => {

						}
					});
					return
				}
				exchangeCardexchange(that.cardPswd, that.userInfo.uid).then(res => {

					if (res.data.succ) {


						uni.showToast({
							title: "兑换成功",
							icon: "success",
							duration: 2000,
							complete: () => {
								that.isHidden = false
								setTimeout(function() {
									wx.reLaunch({
										url: that.url
									})
								}, 1000);
							}
						});


					} else {


						uni.showToast({
							title: res.data.msg,
							icon: "none",
							duration: 2000,
							complete: () => {

							}
						});

					}

				});
			},
			_yxConfigget() {
				yxConfigget().then(res => {
					this.pic = res.data.pic
					this.text = res.data.text
					this.url = res.data.url
				});
			},
		}
	};
</script>
<style scoped>
	.imgicon {
		margin-bottom: 10upx;
		width: 65upx;
	}

	.cardwaibao {
		width: 95%;
		margin: 0 auto;
	}

	.card1 {
		border-radius: 20rpx;
		height: 400rpx;
		background: #fff;
	}

	.card1img {
		width: 100%;
		height: 100%;
	}

	.card2 {
		height: 100rpx;
		background: #fff;
		border-radius: 20rpx;
		margin: 20rpx 0;
	}

	.card3 {
		padding: 30rpx;
		background: #fff;
		border-radius: 20rpx;

	}

	.card3title {
		font-size: 35rpx;
		border-left: 12rpx solid royalblue;
		padding: 0 15rpx;
		margin: 10rpx 0 20rpx 0;
	}

	.card3content {
		font-size: 24rpx;
		word-break: break-all;
		color: #666666;
		line-height: 45rpx;
		text-indent: 2em
	}

	.duihuaninput {
		border-top-left-radius: 15rpx;
		border-bottom-left-radius: 15rpx;
		width: 80%;
		float: left;
		height: 100rpx;
		line-height: 100rpx;
		font-size: 24rpx;
		padding: 20rpx;
	}

	.duihuanbtn {
		background: royalblue;
		color: #fff;
		border-top-right-radius: 15rpx;
		border-bottom-right-radius: 15rpx;
		width: 19%;
		float: right;
		height: 100rpx;
		font-size: 24rpx;
		line-height: 100rpx;
		text-align: center;
	}
</style>
